package script.db

databaseChangeLog(logicalFilePath: 'script/db/hpfm_cusz_model.groovy') {
    changeSet(author: "hzero@hand-china.com", id: "2022-07-01-hpfm_cusz_model") {
        def weight = 1
        if (helper.isSqlServer()) {
            weight = 2
        } else if (helper.isOracle()) {
            weight = 3
        }
        if (helper.dbType().isSupportSequence()) {
            createSequence(sequenceName: 'hpfm_cusz_model_s', startValue: "1")
        }
        createTable(tableName: "hpfm_cusz_model", remarks: "") {
            column(name: "model_id", type: "bigint", autoIncrement: true, remarks: "表ID，主键，供其他表做外键") { constraints(primaryKey: true) }
            column(name: "model_code", type: "varchar(" + 60 * weight + ")", remarks: "模型编码") { constraints(nullable: "false") }
            column(name: "model_name", type: "varchar(" + 120 * weight + ")", remarks: "模型名称") { constraints(nullable: "false") }
            column(name: "service_name", type: "varchar(" + 120 * weight + ")", remarks: "所属服务")
            column(name: "model_table", type: "varchar(" + 120 * weight + ")", remarks: "物理表名称")
            column(name: "primary_key", type: "varchar(" + 120 * weight + ")", remarks: "物理表主键名称")
            column(name: "support_multi_lang", type: "varchar(" + 1 * weight + ")", remarks: "是否为多语言表。1是，0不是")
            column(name: "tenant_id", type: "tinyint", defaultValue: "0", remarks: "租户ID") { constraints(nullable: "false") }
            column(name: "object_version_number", type: "bigint", defaultValue: "1", remarks: "行版本号，用来处理锁") { constraints(nullable: "false") }
            column(name: "created_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "creation_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
            column(name: "last_updated_by", type: "bigint", defaultValue: "-1", remarks: "") { constraints(nullable: "false") }
            column(name: "last_update_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "") { constraints(nullable: "false") }
        }

        addUniqueConstraint(columnNames: "model_code,tenant_id", tableName: "hpfm_cusz_model", constraintName: "hpfm_cusz_model_u1")
    }
}